<?php
/*  
  Copyright (c) 2010-02 SongCMS 
  SongCMS All Rights Reserved. 
  Support:www.SongCMS.com
  QQ:544255858   19951025
  Author:Song  Version:3.17
  Date:2010-08-12 09:28:32
*/

include_once('Admin.php');
!is_numeric($_GET['page']) ? $page = 1 : $page = (int)($_GET['page']);
$PageCount = $GuestBookManagePage;

if(isset($_GET['Action'])){
	if(!is_numeric($_GET['ID']) && $_GET['Action'] != 'Recycled'){
		MsgBox (1,'ID参数出现非数字错误！','-1');
	}
}
$ActionUrl = 'GuestBookManage.php?Lang=' . $Lang . '&page=' . $page;
switch ($_GET['Action']){
	case 'Del':
		if($db->ExecuteSQL("DELETE FROM `" . $dbprefix . "guestbook` WHERE `ID` = '" . $_GET['ID'] . "' LIMIT 1;")){
			AdminLog(3,$Lang,'删除留言信息(ID:' . $_GET['ID'] . ')，结果：操作成功！'); 
			if($WebStaticHTML == 1) MsgBox(0,'',"HtmlComplex.php?Lang={$Lang}&Action=ComplexGuestBook");
			MsgBox (0,'',$ActionUrl);		
		}else{
			AdminLog(3,$Lang,'删除留言信息(ID:' . $_GET['ID'] . ')，结果：操作失败！'); 
			MsgBox (1,'删除留言信息失败！','-1');	
		}
		break;
	case 'y':
		if($db->ExecuteSQL("UPDATE `" . $dbprefix . "guestbook` SET `GuestBookShow` = '1' WHERE `ID` = '" . $_GET['ID'] . "' LIMIT 1 ;")){
			AdminLog(1,$Lang,'通过留言审核(ID:' . $_GET['ID'] . ')，结果：操作成功！'); 
			if($WebStaticHTML == 1) MsgBox(0,'',"HtmlComplex.php?Lang={$Lang}&Action=ComplexGuestBook");
			MsgBox (0,'',$ActionUrl);		
		}else{
			AdminLog(1,$Lang,'通过留言审核(ID:' . $_GET['ID'] . ')，结果：操作失败！'); 
			MsgBox (1,'操作失败！','-1');	
		}
		break;
	case 'n':
		if($db->ExecuteSQL("UPDATE `" . $dbprefix . "guestbook` SET `GuestBookShow` = '0' WHERE `ID` = '" . $_GET['ID'] . "' LIMIT 1 ;")){
			AdminLog(1,$Lang,'取消留言审核(ID:' . $_GET['ID'] . ')，结果：操作成功！'); 
			if($WebStaticHTML == 1) MsgBox(0,'',"HtmlComplex.php?Lang={$Lang}&Action=ComplexGuestBook");
			MsgBox (0,'',$ActionUrl);		
		}else{
			AdminLog(1,$Lang,'取消留言审核(ID:' . $_GET['ID'] . ')，结果：操作失败！'); 
			MsgBox (1,'操作失败！','-1');	
		}	
		break;
	case 'DelAll':
		$_POST['AllDel'] == '' ? MsgBox (1,'操作失败，请选择要删除的留言！','-1') : $AllDel = $_POST['AllDel']; 
		$AllDel = implode(',',$AllDel); //Array转成字串
		if($db->ExecuteSQL("DELETE FROM `" . $dbprefix . "guestbook` WHERE `ID` IN (" . $AllDel . ")")){
			AdminLog(3,$Lang,'批量删除留言信息(ID:' . $AllDel . ')，结果：操作成功！'); 
			if($WebStaticHTML == 1) MsgBox(0,'',"HtmlComplex.php?Lang={$Lang}&Action=ComplexGuestBook");
			unset($AllDel);
			MsgBox (1,'操作成功！',$ActionUrl);		
		} else {
			AdminLog(3,$Lang,'批量删除留言信息，结果：操作失败！'); 
			unset($AllDel);
			MsgBox (1,'操作失败！','-1');		
		}
		break;
	case 'Recycled':
		if($db->ExecuteSQL("DELETE FROM `" . $dbprefix . "guestbook` WHERE `GuestBookLang` = {$Lang}")){
			AdminLog(3,$Lang,'清空所有留言信息，结果：操作成功！'); 
			if($WebStaticHTML == 1) MsgBox(0,'',"HtmlComplex.php?Lang={$Lang}&Action=ComplexGuestBook");
			unset($AllDel);
			MsgBox (1,'操作成功！',$ActionUrl);		
		} else {
			AdminLog(3,$Lang,'清空所有留言信息，结果：操作失败！'); 
			unset($AllDel);
			MsgBox (1,'操作失败！','-1');		
		}
		break;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="./images/adminstyle.css" rel="stylesheet" type="text/css" />
<link rel="Shortcut Icon" href="../favicon.ico">
<link rel="Bookmark" href="../favicon.ico">
<script src="../js/csshovernotie6.js" type="text/javascript"></script>
<script type="text/javascript"> 
function CheckAll(form) { 
	for (var i=0;i<form.elements.length;i++) { 
		var e = form.elements[i]; 
		if (e.Name != "chkAll"&&e.disabled!=true) 
		e.checked = form.chkAll.checked; 
	} 
} 
</script>
</head>

<body>
<br />
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
	<tr class="Notodd">
		<td><?php TopLang();?></td>
		<td align="right">
			<input type="button" value="刷新留言" onClick="javascript:location.href='GuestBookManage.php?Lang=<?php echo $Lang?>'">
			<input type="button" value="清空留言" onClick="javascript:if(confirm('确定要清空所有<?php echo $OnWebLangName?>的留言吗？\n\n该操作不可逆，请谨慎操作！')){location.href='GuestBookManage.php?Action=Recycled&Lang=<?php echo $Lang?>';}">
		</td>
	</tr>
</table>
<table width="98%" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#CCCCCC">
  <form id="form1" name="form1" method="post" action="GuestBookManage.php?ID=0&Action=DelAll&Lang=<?php echo $Lang?>&page=<?php echo $page?>">
  <tr class="odd">
    <td colspan="6" align="center" class="Main_Title">留言管理<?php echo $OnWebLangName?></td>
  </tr>
<tr class="odd">
    <td width="50" align="center">
      <input name="chkAll" type="checkbox" id="chkAll" onclick="CheckAll(this.form)" value="checkbox">    </td>
    <td align="center"><strong>留言者</strong></td>
    <td align="center"><strong>主题</strong></td>
    <td align="center"><strong>留言时间</strong></td>
    <td align="center"><strong>回复状态</strong></td>
    <td align="center"><strong>管理选项</strong></td>
  </tr>
<?php
$SQL = "SELECT `ID`,`GuestBookName`,`GuestBookTitle`,`GuestBookTime`,`GuestBookResumes`,`GuestBookShow` FROM `" . $dbprefix . "guestbook` WHERE GuestBookLang = '" . $Lang . "' "; 
$RsCount = count($db->SelectSQL($SQL));
$SQL .= "ORDER BY `ID` DESC "; 
$SQL .= "LIMIT " . ($page-1)*$PageCount . "," . $PageCount;
foreach ($db->SelectSQL($SQL) as $i => $value){
	$Url = 'GuestBookManage.php?ID=' . $value[0] . '&page=' . $page . '&Lang=' . $Lang . '&Action=';
	$value[4] == NULL ? $Resumes = '<font class="red">×</font>' : $Resumes = '<font class="Igreen">√</font>';
	$manage = '<a href="GuestBookReply.php?Lang=' . $Lang . '&page=' . $page . '&ID=' . $value[0] . '">查看/回复</a>&nbsp;|&nbsp;';
	$value[5] == 0 ? $manage .= '<a href="' . $Url . 'y"><font color="#FF0000">通过审核</font></a>&nbsp;|&nbsp;' : $manage .= '<a href="' . $Url . 'n">取消审核</a>&nbsp;|&nbsp;';
	$manage .= '<a onClick="return confirm(\'确定删除该留言吗？\');" href="' . $Url . 'Del">删除</a>';
	echo '<tr class="odd">
	<td width="50" align="center">
	<input name="AllDel[]" type="checkbox" id="AllDel[]" value="' . $value[0] . '" /></td>
	<td align="center">' . htmlspecialchars($value[1]) . '</td>
	<td align="left">' . htmlspecialchars($value[2]) . '</td>
	<td align="center">' . $value[3] . '</td>
	<td align="center"><strong>' . $Resumes . '</strong></td>
	<td align="center">' . $manage . '</td>
	</tr>';	
}
?>
  <tr class="odd">
    <td align="center"><input onClick="return confirm('确定要删除所有选定的留言吗？');"  type="submit" name="button" id="button" value="删除" /></td>
    <td colspan="5" align="center" height="30"><?php if($RsCount>0) {echo pages('Lang=' . $Lang);} else {echo '没有留言信息！';};?></td>
    </tr>
    </form>
  </table>
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="6">
	<tr class="Notodd">
		<td style="color:#333333; line-height:20px;">
		注：1、未通过审核的留言将不在前台页面中显示；
		</td>
	</tr>
</table>   
<?php unset($SQL,$RsCount,$value,$manage,$i,$Resumes,$Url);  ?>
</body>
</html>
